/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package outils;

import java.awt.Color;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.InputVerifier;
import javax.swing.JComponent;
import javax.swing.JTextField;

/**
 *
 * @author Aude Legrand, Alexandre Becquet
 */
public class VerifChamps extends InputVerifier{
    public static String NOMBRE="[0-9]*";
    public static String TELEPHONE="([0-9]+[ -_/])*[0-9]+";
    public static String EMAIL="([a-zA-Z/\\d_\\\\\\.]+@([a-zA-Z\\d_\\\\\\.]+)"+
                                    "(\\.[a-zA-Z\\d]{2,4}))|([a-zA-Z/\\d_\\\\\\.]+@)"+
                                    "[\\d]{1,3}\\.[\\d]{1,3}\\.[\\d]{1,3}\\.[\\d]{1,3}";
    public static String DATE="(^((((0[1-9])|([1-2][0-9])|(3[0-1]))|([1-9]))\\x2F(((0[1-9])|(1[0-2]))|([1-9]))\\x2F(([0-9]{2})|(((19)|([2]([0]{1})))([0-9]{2}))))$)";
    public static String TEXTCHAR="[a-zA-Z]*";
    public String myExpReg;

    public VerifChamps(String valeur){
        this.myExpReg=valeur;
    }
    
    @Override
    
    public boolean verify(JComponent input) {
       JTextField field = (JTextField)input;
       String text = field.getText().trim();
       Pattern p = Pattern.compile(myExpReg);
       Matcher m = p.matcher(text);
       if (m.matches()) {
           field.setBackground(new Color(0xFF, 0xFF, 0xFF));
           return true;
       }else{
           field.setBackground(new Color(0xFF, 0xD7, 0xD7));
           return false;
       }
    }

}
